﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.DynamicData;
using NotAClue.ComponentModel.DataAnnotations;

namespace NotAClue.Web.DynamicData.Controls.FilteredForeignKey
{
    public class FilteredForeignKey : FieldTemplateUserControl
    {
        protected new void PopulateListControl(ListControl listControl)
        {
            foreach (object obj2 in Table.GetQuery().ApplyColumnFilter(this.ForeignKeyColumn.ParentTable))
            {
                string displayString = Table.GetDisplayString(obj2);
                string primaryKeyString = Table.GetPrimaryKeyString(obj2);
                listControl.Items.Add(new ListItem(displayString, primaryKeyString.TrimEnd(new char[0])));
            }
        }

        //protected void PopulateListControl(ListControl listControl)
        //{
        //    if (this.Column is MetaForeignKeyColumn)
        //    {
        //        Misc.FillListItemCollection(this.ForeignKeyColumn.ParentTable, listControl.Items);
        //    }
        //    else
        //    {
        //        Type type;
        //        if (this.Column.IsEnumType(out type))
        //        {
        //            this.FillEnumListControl(listControl, type);
        //        }
        //    }
        //}

        //public static void FillListItemCollection(IMetaTable table, ListItemCollection listItemCollection)
        //{
        //    foreach (object obj2 in table.GetQuery())
        //    {
        //        string displayString = table.GetDisplayString(obj2);
        //        string primaryKeyString = table.GetPrimaryKeyString(obj2);
        //        listItemCollection.Add(new ListItem(displayString, primaryKeyString.TrimEnd(new char[0])));
        //    }
        //}
    }
}
